#include "stdafx.h"
#include "Int32Value.h"
#include "../Config.h"
#include "../CfgUtil.h"

using namespace pb::cfg;

Int32Value::Int32Value(Config* cfg, const std::string& name)
    : Value(cfg, name, Value::eInt32)
    , m_data(0)
{
}

Int32Value::~Int32Value()
{
}

bool
Int32Value::loadData(std::fstream& in)
{
    unsigned int length = 0;
    if (!Util::loadLength(in, length) || (length != 4)  || !lengthOfData(length))
        return false;

    in.read((char*)&m_data, 4);
    if (in.eof())
        return false;

    return true;
}

void
Int32Value::saveData(std::fstream& out)
{
    out.write((char*)&m_data, 4);
}

__int32
Int32Value::data() const
{
    return m_data;
}

void
Int32Value::data(__int32 data)
{
    if (lengthOfData(4))
    {
        m_data = data;
        m_cfg->onValueChanged();
    }
}